package com.baidu.structs;

import com.baidu.aip.imagesearch.AipImageSearch;
import org.json.JSONObject;

import java.util.HashMap;

public class AipPicSearch {

    public static final String APP_ID = "***";
    public static final String API_KEY = "***";
    public static final String SECRET_KEY = "***";

    public static AipImageSearch client = new AipImageSearch(APP_ID, API_KEY, SECRET_KEY);


    private AipPicSearch() {
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);
    }

    private static AipPicSearch ourInstance = new AipPicSearch();

    public static AipPicSearch getInstance() {
        return ourInstance;
    }



    public AipImageSearch getAipClient() {
        return client;
    }

    public String getBrief(String image) {
        JSONObject res = client.sameHqSearch(image, new HashMap<String, String>());
        System.out.println("res  "+ res);
        String brief = "";
        try {
            brief = res.getJSONArray("result").getJSONObject(0).get("brief").toString();
        }catch (Exception e) {
            e.printStackTrace();
        }
        return brief;
    }
}
